﻿using System.Collections.Specialized;
using System.IO;

namespace MyWcfRestLib.Files
{
    class TwoPathOpParams : FileOpParams
    {
        public const string FromPathKey = "from_path";
        public const string ToPathKey = "to_path";
        public string FromPath { get; private set; }
        public string ToPath { get; private set; }

        public TwoPathOpParams(string basePath, NameValueCollection requestQueryParams, Stream requestBody = null)
            : base(basePath, requestQueryParams, requestBody)
        {

            // Fix from path string
            FromPath = (string)QueryParams[FromPathKey];
            if (null != FromPath)
            {
                FromPath = FromPath.Trim(InvalidFileNameChars);
            }

            // fix ToPath string
            ToPath = (string)QueryParams[ToPathKey];
            if (null != ToPath)
            {
                ToPath = ToPath.Trim(InvalidFileNameChars);
            }

        }

        override public bool IsValid
        {
            get
            {
                if ((!UtilityFunctions.IsValidPathName(DeviceRoot)) || (!UtilityFunctions.IsValidPathName(FromPath)) || (!UtilityFunctions.IsValidPathName(ToPath)))
                    return false;
                else
                    return true;
            }
        }

    }

}
